package com.lovo.csc.controller;



import com.lovo.csc.dto.PurchaseTenderDto;
import com.lovo.csc.entity.Purchasetender;
import com.lovo.csc.service.IPurchasetenderService;
import com.lovo.util.MQUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-07
 */
@RestController
@RequestMapping("/purchasetender")
@Api(value = "生产采购标书,舒得强")
public class PurchasetenderController {

    @Autowired
    IPurchasetenderService purchasetenderService;

    @Autowired
    RabbitTemplate rabbitTemplate;

    @PostMapping("purchaseTender")
    @ApiOperation(value = "采购标书上传到MQ,以及持久化到本地")
    public boolean purchaseTender(PurchaseTenderDto purchaseTenderDto){
        if (purchaseTenderDto!=null){
            Purchasetender purchasetender = new Purchasetender();
            purchasetender.setGoodname(purchaseTenderDto.getGoodName());
            purchasetender.setGoodsort(purchaseTenderDto.getGoodSort());
            purchasetender.setGoodinfo(purchaseTenderDto.getGoodInfo());
            purchasetender.setPurchasenum(purchaseTenderDto.getPurchaseNum());
            purchasetender.setPurchasecode(purchaseTenderDto.getPurchaseCode());
            purchasetender.setPurchasestate(purchaseTenderDto.getPurchaseState());
            purchasetenderService.save(purchasetender);
            rabbitTemplate.convertAndSend(MQUtil.tenderDirectExchange,MQUtil.tenderKey,purchaseTenderDto);
        }
        return true;
    }
}
